<template>
    <div class="user-div">
        <el-card class="box-card">
            <div slot="header" class="clearfix">
                <div>
                    <el-input placeholder="搜索" suffix-icon="el-icon-search" v-model="searchContent">
                    </el-input>
                </div>
                <div>
                    <el-button type="primary">新增</el-button>
                    <el-button type="danger">删除</el-button>
                </div>
            </div>
            <div class="text item">
                <el-table :data="userList" border style="width: 100%;" ref="multipleTable"
                    @selection-change="handleSelectionChange" v-loading="loading">
                    <el-table-column type="selection" width="55">
                    </el-table-column>
                    <el-table-column prop="id" label="ID" width="200">
                    </el-table-column>
                    <el-table-column prop="username" label="账号" width="150">
                    </el-table-column>
                    <el-table-column prop="name" label="昵称" width="150">
                    </el-table-column>
                    <el-table-column prop="phone" label="联系方式" width="150">
                    </el-table-column>
                    <el-table-column prop="avatar" label="头像" width="100">
                        <template slot-scope="scope">
                            <el-avatar :size="50" :src="scope.row.avatar"></el-avatar>
                        </template>
                    </el-table-column>
                    <el-table-column prop="age" label="年龄" width="80">
                    </el-table-column>
                    <el-table-column prop="sex" label="性别" width="80">
                        <template slot-scope="scope">
                            <span v-show="scope.row.sex == 1">男</span>
                            <span v-show="scope.row.sex == 2">女</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="status" label="状态" width="80">
                        <template slot-scope="scope">
                            <el-tag type="success" v-show="scope.row.status == 1">正常</el-tag>
                            <el-tag type="danger" v-show="scope.row.status == 2">禁用</el-tag>
                        </template>
                    </el-table-column>
                    <el-table-column fixed="right" label="操作" width="140">
                        <template slot-scope="scope">
                            <el-button type="text" size="small" @click="">编辑</el-button>
                            <el-button type="text" size="small" @click="">删除</el-button>
                        </template>
                    </el-table-column>
                </el-table>
            </div>
            <div class="pagination">
                <el-pagination background layout="prev, pager, next" :total="1000">
                </el-pagination>
            </div>
        </el-card>
    </div>
</template>

<script>
export default {
    name: 'UserList',
    data() {
        return {
            // 是否加载
            loading: false,
            // 搜索内容
            searchContent: "",
            // 多选数据
            multipleSelection: [],
            // 当前页数
            currentPag: 1,
            // 每页大小
            pageSize: 10,
            // 总页数
            totalPage: 0,

        }
    },
    mounted() {
        this.init()
    },
    methods: {
        // 获取表格数据
        async init() {
            this.loading = true
            let res = await this.$store.dispatch('getUserPag')
            if (!res.success) this.$myfun.resError(res)
            this.loading = false
        },
        // 多选
        handleSelectionChange(val) {
            this.multipleSelection = val
        },
    },
    computed: {
        userList() {
            return this.$store.state.user.userList
        }
    }
}
</script>

<style scoped>
.clearfix {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.pagination {
    padding: 20px 0 10px 0;
    text-align: center;
}
</style>